﻿using System;
using System.Collections.Generic;
using System.Text;

namespace ElasticSearchTest
{
    public class EsIndexConfig
    {
        public static EsIndexConfig Instance => new EsIndexConfig();

        public static string prefix = ""; //uat_
        public static string suffix = "";

        public string _defaultIndex = "defaultindex";
        //index名称使用别名
        public readonly string _schoolIndexName = "school";
        public readonly string _schoolRankIndexName = "schoolrank";
        public readonly string _commentIndexName = "comment";
        public readonly string _questionIndexName = "question";
        public readonly string _answerIndexName = "answer";
        public readonly string _liveIndexName = "live";
        public readonly string _articleIndexName = "article";
        public readonly string _singSchoolIndexName = "sign";
        public readonly string _BTschoolSearchIndexName = "schsearch";


        public readonly Index TopicIndex= new Index("topicindex", "topic");
        public readonly Index CircleIndex = new Index("circleindex", "circle");
        public readonly Index TalentIndex = new Index("talentindex", "talent");

        public readonly Index SchoolIndex = new Index("schoolindex_09", "school");
        public readonly Index CommentIndex = new Index("commentindex_03", "comment");
        public readonly Index QuestionIndex = new Index("questionindex_03", "question");
        public readonly Index ArticleIndex = new Index("articleindex_06", "article");
        public readonly Index LiveIndex = new Index("liveindex_01", "live");
        public readonly Index SchoolRankIndex = new Index("schoolrankindex", "schoolrank");
        public readonly Index UniversityIndex = new Index("universityindex", "university");

        public readonly Index CourseIndex = new Index("courseindex", "course");
        public readonly Index EvaluationIndex = new Index("evaluationindex", "evaluation");

        public readonly Index HistoryIndex = new Index("historyindex", "history");
        public readonly Index KeywordIndex = new Index("keywordindex", "keyword");
        public readonly Index CdnLogIndex = new Index("cdnlog2021", "");

        public class Index
        {
            public Index(string name, string alias)
            {
                Name = WrapIndex(name ?? throw new ArgumentNullException(nameof(name)));
                Alias = WrapIndex(alias ?? throw new ArgumentNullException(nameof(alias)));
            }

            public string Name { get; private set; }
            public string Alias { get; private set; }

            public static string WrapIndex(string name)
            {
                return prefix + name + suffix;
            }

            public string SearchIndex
            {
                get
                {
                    return !string.IsNullOrWhiteSpace(Alias) ? Alias : Name;
                }
            }
        }

    }
}
